//
//  CKCollectionViewItem.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/3/4.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation


class CKCollectionViewItem: NSCollectionViewItem {
    static let identifier =  NSUserInterfaceItemIdentifier.init("CKCollectionViewItem")
    
    override func viewDidLayout() {
        super.viewDidLayout()
        self.setupUI()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    lazy var aleView: ALExItemView = {
        let view = ALExItemView()
        return view
    }()
    
    var isHover:Bool = true {
        didSet {
            let borderColor = isHover ? color_main108:color_gray(200)
            self.view.zh_border(radius: 5, borderColor: borderColor, borderWidth: 1)
        }
    }
    
    var isSelect:Bool = true {
        didSet {
            let color = isSelect ? color_main108:NSColor.white
            self.view.layer?.backgroundColor = color.cgColor
            
            let labColor = isSelect ? NSColor.white:NSColor.black
            self.ctitle.textColor = labColor
            
            let borderColor = isSelect ? color_main108:color_gray(200)
            self.view.zh_border(radius: 5, borderColor: borderColor, borderWidth: 1)
        }
    }
    
    
    func setupUI()  {
        self.view.wantsLayer = true
        
        self.view.addSubview(aleView)
        aleView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        self.view.addSubview(ctitle)
        ctitle.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(20)
            make.bottom.equalToSuperview().offset(-5)
            make.centerX.equalToSuperview()
        }
        
        self.view.addSubview(iconImageV)
        iconImageV.snp.makeConstraints { (make) in
            make.width.equalTo(100)
            make.height.equalTo(75)
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(-15)
        }
        
        self.isHover = false
        self.isSelect = false
    }
    
    lazy var iconImageV: NSImageView = {
        let imageV = NSImageView.init(image: NSImage.image(name:"ic_logo_blue")!)
        return imageV
    }()
    
    lazy var ctitle: NSLabel = {
        let lab = NSLabel.label(title: "nihao", textColor: NSColor.black, font: NSFont.systemFont(ofSize: 12))
        lab.alignment = .center
        return lab
    }()
    
    
    
    
}

extension CKCollectionViewItem {
    
    override func mouseEntered(with event: NSEvent) {
        super.mouseEntered(with: event)
        self.isHover = true
    }
    override func mouseExited(with event: NSEvent) {
        super.mouseExited(with: event)
        self.isHover = false
    }
    
    override func mouseDragged(with event: NSEvent) {
        super.mouseDragged(with: event)
        print(#function)
    }
    
}
